package com.dream.wukong.common.core.jdbc.generator;

import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;

import java.util.HashMap;

/**
 * @Author: wuyichao
 * @Description:
 * @Date: Created in 10:14 2018/9/18.
 * @Modified:
 * 需要数据库提供对序列号的支持，Oracle支持。
 */
public class SequenceGenerator implements IdGenerator {
    public static final String 	SEQUENCE ="SEQUENCE" ;

    private String sequence ;
    private NamedParameterJdbcOperations jdbc ;
    @Override
    public Object generateValue( ) {
        String sql = "SELECT " + sequence + ".NEXTVAL FROM DUAL ";
        return jdbc.queryForObject(sql, new HashMap(), Long.class);
    }
    public void setSequence(String sequence) {
        this.sequence = sequence;
    }
    public void setJdbc(NamedParameterJdbcOperations jdbc) {
        this.jdbc = jdbc;
    }

}